//
//  RCMerchantDetailCell.m
//  RocketProject
//
//  Created by chen jiedan on 13-7-5.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCMerchantDetailCell.h"
#import "CommonDefines.h"
#import "UIColor-Expanded.h"
#import "TTTAttributedLabel.h"
#import "NSAttributedString+LVAddition.h"
#import <QuartzCore/QuartzCore.h>
#import "NSString+NSString_Ex_.h"
#import "UIImageView+WebCache.h"
#import "RCMapViewController.h"
#import "RCOrderVC.h"
#import "RCActivityOrderViewController.h"
#import "GloableEngineService.h"
#import "AppDelegate.h"
#import "RCMemberCardVC.h"
#import "UIImageView+WebCache.h"
#import "NSArray+EX.h"

#define kLineImageFile           @"image_line_type3.png"

#define kBGImageFile             @"image_member_cell_bg.png"
#define kDefaultImageFile        @"image_default.png"
#define kStartActiveImageFile    @"image_start_active.png"
#define kStartInActiveImageFile  @"image_merchant_inactive.png"
#define kOrderServerImageFile    @"image_merchant_orderServer.png"
#define kPhoneOrderImageFile     @"image_merchant_phoneOrder.png"
#define kAddOrderImageFile       @"image_merchant_addOrder.png"
#define kPointImageFile          @"image_merchant_point.png"
#define kHighlightImageFile      @"image_merchant_highlight.png"
#define kOpentimeImageFile       @"image_merchant_opentime.png"
#define kDescImageFile           @"image_merchant_description.png"
#define kCellArrowImageFile      @"image_merchant_cell_arrow.png"
#define kCellMiddleLineImageFile @"image_merchant_cell_middleLine.png"
#define kCommentMedalImageFile   @"image_merchant_medal.png"
#define kDiscountImageFile       @"image_merchant_discount.png"
#define kOtherShopImageFile      @"image_merchant_shop.png"
#define kAvatarDefaultImageFile  @"image_merchant_avatar_default.png"
#define kDefaultimageFile        @"image_recommendFood_image_bg.png"


@implementation RCMerchantDetailHeaderCell{
    UILabel *_merchantNameLabel;
    UILabel *_serviceLabel;
    UILabel *_priceLabel;
    UILabel *_sanitationLabel;
    UILabel *_tasteLabel;
    UILabel *_environmentLabel;
    UIImageView *_placeImageView;
    UILabel *_distanceLabel;
    UIImageView *_lineImageView;
    UIImageView *_merchantImageView;
    UIButton    *_transParentButton;
    UIImageView *_startImageView1;
    UIImageView *_startImageView2;
    UIImageView *_startImageView3;
    UIImageView *_startImageView4;
    UIImageView *_startImageView5;
    UILabel     *_scoreLabel;
}
@synthesize delegate = _delegate;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]];
        self.layer.contents = (id)bgImage.CGImage;
        [self.contentView setBackgroundColorWithImage:bgImage];
        [self setUpView];
    }
    return self;
}

-(void)dealloc{
    self.delegate = nil;
    [super dealloc];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    
}


- (void) setUpView
{
    _merchantNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 13, 280, 20)];
    _merchantNameLabel.font = [UIFont fontWithName:kFontNameHeiti size:19];
    _merchantNameLabel.textColor = [UIColor colorWithHex:0xff505050];
    _merchantNameLabel.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:_merchantNameLabel];
    [_merchantNameLabel release];
    
    UIImageView *defaultImageView = [[UIImageView alloc]initWithFrame:CGRectMake(14, 44, 112, 82)];
    [defaultImageView setImage:[UIImage imageNamed:kDefaultImageFile]];
    [self addSubview:defaultImageView];
    [defaultImageView release];
    
    _merchantImageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 45, 110, 80)];
    _merchantImageView.backgroundColor = [UIColor clearColor];
    [self addSubview:_merchantImageView];
    [_merchantImageView release];
    
    _transParentButton = [[UIButton alloc]initWithFrame:_merchantImageView.frame];
    _transParentButton.backgroundColor = [UIColor clearColor];
    [_transParentButton addTarget:self action:@selector(transparentButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    _transParentButton.hidden = YES;
    [self addSubview:_transParentButton];
    [_transParentButton release];
    
    _startImageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(140, 50, 14, 14)];
    _startImageView1.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView1];
    [_startImageView1 release];
    
    _startImageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(155, 50, 14, 14)];
    _startImageView2.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView2];
    [_startImageView2 release];
    
    _startImageView3 = [[UIImageView alloc]initWithFrame:CGRectMake(170, 50, 14, 14)];
    _startImageView3.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView3];
    [_startImageView3 release];
    
    _startImageView4 = [[UIImageView alloc]initWithFrame:CGRectMake(185, 50, 14, 14)];
    _startImageView4.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView4];
    [_startImageView4 release];
    
    _startImageView5 = [[UIImageView alloc]initWithFrame:CGRectMake(200, 50, 14, 14)];
    _startImageView5.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView5];
    [_startImageView5 release];
    
    _scoreLabel = [[UILabel alloc]initWithFrame:CGRectMake(217, 50, 20, 16)];
    _scoreLabel.backgroundColor = [UIColor clearColor];
    _scoreLabel.textColor = [UIColor redColor];
    _scoreLabel.font = [UIFont fontWithName:kFontNameHelvetica size:16];
    [self addSubview:_scoreLabel];
    [_scoreLabel release];
    
    UIImage *img = [UIImage imageNamed:@"image_allCity_district"];
    _placeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(253, 52, img.size.width, img.size.height)];
    _placeImageView.image = img;
    [self addSubview:_placeImageView];
    [_placeImageView release];
    
    
    _distanceLabel = [[UILabel alloc] initWithFrame:CGRectMake(253+img.size.width+5, 50, 70, 14)];
    _distanceLabel.font = [UIFont fontWithName:kFontNameHelvetica size:14];
    _distanceLabel.textColor = [UIColor colorWithHex:0xff989797];
    _distanceLabel.backgroundColor = [UIColor clearColor];
    [self addSubview:_distanceLabel];
    [_distanceLabel release];
    
    _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 75, 200, 14)];
    _priceLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    _priceLabel.textColor = [UIColor colorWithHex:0xff989797];
    _priceLabel.backgroundColor = [UIColor clearColor];
    [self addSubview:_priceLabel];
    [_priceLabel release];
    
    _environmentLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 98, 60, 14)];
    _environmentLabel.backgroundColor = [UIColor clearColor];
    _environmentLabel.font = [UIFont systemFontOfSize:14];
    _environmentLabel.textColor = [UIColor colorWithHex:0xff989797];
    [self addSubview:_environmentLabel];
    [_environmentLabel release];
    
    _sanitationLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 98, 60, 14)];
    _sanitationLabel.backgroundColor = [UIColor clearColor];
    _sanitationLabel.font = [UIFont systemFontOfSize:14];
    _sanitationLabel.textColor = [UIColor colorWithHex:0xff989797];
    [self addSubview:_sanitationLabel];
    [_sanitationLabel release];
    
    _tasteLabel = [[UILabel alloc] initWithFrame:CGRectMake(255, 98, 60, 14)];
    _tasteLabel.backgroundColor = [UIColor clearColor];
    _tasteLabel.font = [UIFont systemFontOfSize:14];
    _tasteLabel.textColor = [UIColor colorWithHex:0xff989797];
    [self addSubview:_tasteLabel];
    [_tasteLabel release];
    
    _serviceLabel = [[UILabel alloc] initWithFrame:CGRectMake(320, 98, 60, 14)];
    _serviceLabel.font = [UIFont systemFontOfSize:14];
    _serviceLabel.textColor = [UIColor colorWithHex:0xff989797];
    _serviceLabel.backgroundColor = [UIColor clearColor];
    [self addSubview:_serviceLabel];
    [_serviceLabel release];
    
    
    
    _lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 129, 320, 1)];
    _lineImageView.backgroundColor = [UIColor clearColor];
    NSString *filePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kLineImageFile];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
    [self.contentView addSubview:_lineImageView];
    [_lineImageView release];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;

    
}
- (void) bindData:(RCMerchantDetailDataModel *)detailModel
{
    if (nil == detailModel) {
        return;
    }
    _merchantNameLabel.text = detailModel.merchantName;
    
    NSInteger score = detailModel.merchantScore;
    NSString *resourcePath = [[NSBundle mainBundle]resourcePath];
    UIImage *activeImage = [UIImage imageWithContentsOfFile:[resourcePath stringByAppendingPathComponent:kStartActiveImageFile]];
    UIImage *inactiveImage = [UIImage imageWithContentsOfFile:[resourcePath stringByAppendingPathComponent:kStartInActiveImageFile]];
    [_startImageView1 setImage:score > 0 ? activeImage : inactiveImage];
    [_startImageView2 setImage:score > 1 ? activeImage : inactiveImage];
    [_startImageView3 setImage:score > 2 ? activeImage : inactiveImage];
    [_startImageView4 setImage:score > 3 ? activeImage : inactiveImage];
    [_startImageView5 setImage:score > 4 ? activeImage : inactiveImage];
    
    _scoreLabel.text = [NSString stringWithFormat:@"%d",score];


    NSString *distance = nil;
    if ([detailModel.merchantDistance floatValue] > 1000) {
        float distanceKm = [detailModel.merchantDistance floatValue]/1000.0;
        if ( ((int)distanceKm) > 999 )
            distance = [NSString stringWithFormat:@"%d+km",999];
        else
            distance = [NSString stringWithFormat:@"%.1fkm",distanceKm];
    }else{
        distance = [NSString stringWithFormat:@"%@m",detailModel.merchantDistance];
    }
    _distanceLabel.text = distance;
    
    _transParentButton.hidden = YES;
    if (![NSString stringIsNullOrEmpty:detailModel.merchantImageUrl]) {
        [_merchantImageView setImageWithURL:[NSURL URLWithString:detailModel.merchantImageUrl] placeholderImage:[UIImage imageNamed:kDefaultImageFile]];
        _transParentButton.hidden = NO;
    }
    
    if (![NSString stringIsNullOrEmpty:detailModel.merchantPrice]) {
        _priceLabel.text = detailModel.merchantPrice;
    }else{
        _priceLabel.text = @"";
    }
    
    CGFloat width = 140;
    _environmentLabel.hidden = YES;
    if (![NSString stringIsNullOrEmpty:detailModel.merchantEnvironment]) {
        _environmentLabel.hidden = NO;
        _environmentLabel.text = detailModel.merchantEnvironment;
        _environmentLabel.frame = CGRectMake(width, 98, 60, 14);
        width +=60;
    }
    
    _sanitationLabel.hidden = YES;
    if (![NSString stringIsNullOrEmpty:detailModel.merchantSanitation]) {
        _sanitationLabel.hidden = NO;
        _sanitationLabel.text = detailModel.merchantSanitation;
        _sanitationLabel.frame = CGRectMake(width, 98, 60, 14);
        width +=60;
    }
    
    _tasteLabel.hidden = YES;
    if (![NSString stringIsNullOrEmpty:detailModel.merchantTaste]) {
        _tasteLabel.hidden = NO;
        _tasteLabel.text = detailModel.merchantTaste;
        _tasteLabel.frame = CGRectMake(width, 98, 60, 14);
        width +=60;
    }
    
    _serviceLabel.hidden = YES;
    if (![NSString stringIsNullOrEmpty:detailModel.merchantService]) {
        _serviceLabel.hidden = NO;
        _serviceLabel.text = detailModel.merchantService;
        _serviceLabel.frame = CGRectMake(width, 98, 60, 14);
    }
    
    
    
}

-(void)transparentButtonClicked{
    if (_delegate && [_delegate respondsToSelector:@selector(gotoPictureAlbumView)]) {
        [_delegate gotoPictureAlbumView];
    }
}

@end


@implementation RCMerchantDetailOnelineCell{
    UIImageView *_iconImageView;
    UILabel *_typeTitleLabel;
    TTTAttributedLabel *_typeContentLabel;
    UIImageView *_pointImageView;
    UILabel     *_pointLabel;
    UIButton *_cellButton;
    RCMerchantDetailItem *_dataModel;
    UIWebView *_phoneWebView;
    CLLocationCoordinate2D _location;
    NSString *_merchantName;
    NSString *_merchantID;
    UIView *_rightView;
    
}

@synthesize dataModel = _dataModel;
@synthesize cellType = _cellType;
@synthesize parentViewController = _parentViewController;
@synthesize location = _location;
@synthesize merchantName = _merchantName;
@synthesize merchantID = _merchantID;

- (id) initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]];
        self.layer.contents = (id)bgImage.CGImage;
        [self.contentView setBackgroundColorWithImage:bgImage];
        [self setUpView];
    }
    return self;
}

-(void)dealloc{
    self.dataModel = nil;
    self.merchantID = nil;
    self.merchantName = nil;
    self.parentViewController = nil;
    [_phoneWebView release];
    _phoneWebView = nil;
    [super dealloc];
}


- (void) setUpView
{
    
    _iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 13, 8, 10)];
//    _iconImageView.image = img;
    [self addSubview:_iconImageView];
    [_iconImageView release];
    
    
    _typeTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 13, 60, 18)];
    _typeTitleLabel.font = [UIFont fontWithName:kFontNameHeiti size:18];
    _typeTitleLabel.textColor = [UIColor colorWithHex:0xff505050];
    _typeTitleLabel.backgroundColor = [UIColor clearColor];
    [self addSubview:_typeTitleLabel];
    [_typeTitleLabel release];
    
    
    _typeContentLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(30, 13, 140, 100)];
    _typeContentLabel.leading = 6;
    _typeContentLabel.numberOfLines = 0;
    _typeContentLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:15];
    _typeContentLabel.textColor = [UIColor colorWithHex:0xff505050];
    _typeContentLabel.backgroundColor = [UIColor clearColor];
    _typeContentLabel.userInteractionEnabled = NO;
    [self addSubview:_typeContentLabel];
    [_typeContentLabel release];
    
    _pointImageView = [[UIImageView alloc]initWithFrame:CGRectMake(85, 15, 38, 13)];
    _pointImageView.backgroundColor = [UIColor clearColor];
    NSString *filePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kPointImageFile];
    [_pointImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
    
    _pointLabel = [[UILabel alloc]initWithFrame:CGRectMake(11, 3, 27, 9)];
    if ([[[UIDevice currentDevice]systemVersion]floatValue] >=7.0) {
        _pointLabel.frame = CGRectMake(11, 1.5, 27, 9);
    }
    _pointLabel.backgroundColor = [UIColor clearColor];
    _pointLabel.textColor = [UIColor colorWithHex:0xfff99a63];
    _pointLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:8];
    [_pointImageView addSubview:_pointLabel];
    [_pointLabel release];
    
    [self addSubview:_pointImageView];
    [_pointImageView release];
    
    
    _rightView = [[UIView alloc]initWithFrame:CGRectMake(175, 0, 145, 39)];
    _rightView.backgroundColor = [UIColor clearColor];
    [self addSubview:_rightView];
    [_rightView release];
    
    _cellButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 320, 100)];
    _cellButton.backgroundColor = [UIColor clearColor];
    [_cellButton addTarget:self action:@selector(cellButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_cellButton];
    [_cellButton release];

    
}
- (void) bindData:(RCMerchantDetailItem *)detailModel
{
    if (nil == detailModel) {
        return;
    }
    self.dataModel = detailModel;
    _typeContentLabel.text = detailModel.content;
    
    if (detailModel.type == kMerchantDetailType_Address) {
        _typeContentLabel.frame = CGRectMake(30, 13, 250, 100);
    }else if (detailModel.type == kMerchantDetailType_Order){
        _typeContentLabel.frame = CGRectMake(14, 13, 154, 100);
        _typeContentLabel.text = detailModel.title;
    }else{
        _typeContentLabel.frame = CGRectMake(30, 13, 140, 100);
    }
    
    CGFloat contentWidth = _typeContentLabel.frame.size.width;
    
    NSAttributedString *attributedStr = _typeContentLabel.attributedText;
    CGSize restSize = [attributedStr sizeWithConstrainedToSize:CGSizeMake(contentWidth, 2000) Leading:6];
    _typeContentLabel.frame = CGRectMake(_typeContentLabel.frame.origin.x, 13, contentWidth, restSize.height);
    
    CGFloat cellHeight = 13 + restSize.height + 13;
    
    _rightView.frame = CGRectMake(175, 0, 145, cellHeight);
    
    if (detailModel.type == kMerchantDetailType_Phone) {
        UIImage *img = [UIImage imageNamed:@"detail_phone_icon"];
        _iconImageView.image = img;
        _iconImageView.frame = CGRectMake(14, 15, 8, 10);
        _pointImageView.hidden = YES;
        
        for (UIView *view in [_rightView subviews]) {
            [view removeFromSuperview];
        }
        
        UIImageView *middleView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1, cellHeight)];
        middleView.backgroundColor = [UIColor clearColor];
        NSString *middlePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kCellMiddleLineImageFile];
        [middleView setImage:[UIImage imageWithContentsOfFile:middlePath]];
        [_rightView addSubview:middleView];
        [middleView release];
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, (cellHeight-12)/2, 12, 12)];
        imageView.backgroundColor = [UIColor clearColor];
        [imageView setImage:[UIImage imageNamed:kPhoneOrderImageFile]];
        [_rightView addSubview:imageView];
        [imageView release];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(33, (cellHeight-17)/2, 100, 17)];
        label.backgroundColor = [UIColor clearColor];
        label.font = [UIFont fontWithName:kFontNameHeiti size:17];
        label.textColor = [UIColor colorWithHex:0xff505050];
        label.text = @"电话预订";
        [_rightView addSubview:label];
        [label release];
        
    }else if (detailModel.type == kMerchantDetailType_Address){
        UIImage *img = [UIImage imageNamed:@"image_allCity_district"];
        _iconImageView.image = img;
        _iconImageView.frame = CGRectMake(14, 15, 8, 10);
        _pointImageView.hidden = YES;
        
        for (UIView *view in [_rightView subviews]) {
            [view removeFromSuperview];
        }
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(124, (cellHeight-10)/2, 7, 10)];
        imageView.backgroundColor = [UIColor clearColor];
        [imageView setImage:[UIImage imageNamed:kCellArrowImageFile]];
        [_rightView addSubview:imageView];
        [imageView release];
        
    }else if (detailModel.type == kMerchantDetailType_Traffic || detailModel.type == kMerchantDetailType_Othershop){
        UIImage *img = nil;
        if (detailModel.type == kMerchantDetailType_Othershop) {
            
            img = [UIImage imageNamed:kOtherShopImageFile];

        }else{
            img = [UIImage imageNamed:kOpentimeImageFile];
        }
        _iconImageView.image = img;
        _iconImageView.frame = CGRectMake(14, 15, 12, 12);
        _pointImageView.hidden = YES;
        _typeContentLabel.frame = CGRectMake(30, 15, 260, 15);
        
        for (UIView *view in [_rightView subviews]) {
            [view removeFromSuperview];
        }
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(124, (cellHeight-10)/2, 7, 10)];
        imageView.backgroundColor = [UIColor clearColor];
        [imageView setImage:[UIImage imageNamed:kCellArrowImageFile]];
        [_rightView addSubview:imageView];
        [imageView release];
    }else if (detailModel.type == kMerchantDetailType_Order){
        _iconImageView.image = nil;
        if (![NSString stringIsNullOrEmpty:detailModel.content]) {
            _pointImageView.hidden = NO;
            
            _pointLabel.text = [NSString stringWithFormat:@"%@积分",detailModel.content];
        }else{
            _pointImageView.hidden = YES;
        }
        
        
        UIImageView *middleView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1, cellHeight)];
        middleView.backgroundColor = [UIColor clearColor];
        NSString *middlePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kCellMiddleLineImageFile];
        [middleView setImage:[UIImage imageWithContentsOfFile:middlePath]];
        [_rightView addSubview:middleView];
        [middleView release];
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, (cellHeight-12)/2, 12, 12)];
        imageView.backgroundColor = [UIColor clearColor];
        [imageView setImage:[UIImage imageNamed:kAddOrderImageFile]];
        [_rightView addSubview:imageView];
        [imageView release];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(33, (cellHeight-17)/2, 100, 17)];
        label.backgroundColor = [UIColor clearColor];
        label.font = [UIFont fontWithName:kFontNameHeiti size:17];
        label.textColor = [UIColor colorWithHex:0xff505050];
        label.text = @"在线预订";
        [_rightView addSubview:label];
        [label release];
        
    }else if (detailModel.type == kMerchantDetailType_OrderServer){
        NSString *filePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kOrderServerImageFile];
        _iconImageView.frame = CGRectMake(14, 15, 12, 12);
        [_iconImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
        _pointImageView.hidden = YES;
        
        UIImageView *middleView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1, cellHeight)];
        middleView.backgroundColor = [UIColor clearColor];
        NSString *middlePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kCellMiddleLineImageFile];
        [middleView setImage:[UIImage imageWithContentsOfFile:middlePath]];
        [_rightView addSubview:middleView];
        [middleView release];
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, (cellHeight-12)/2, 12, 12)];
        imageView.backgroundColor = [UIColor clearColor];
        [imageView setImage:[UIImage imageNamed:kAddOrderImageFile]];
        [_rightView addSubview:imageView];
        [imageView release];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(33, (cellHeight-17)/2, 100, 17)];
        label.backgroundColor = [UIColor clearColor];
        label.font = [UIFont fontWithName:kFontNameHeiti size:17];
        label.textColor = [UIColor colorWithHex:0xff505050];
        label.text = @"加入会员";
        [_rightView addSubview:label];
        [label release];
        
    }
    
    _cellButton.frame = CGRectMake(0, 0, 320, 15+restSize.height+10);
    if (detailModel.type == kMerchantDetailType_Traffic || detailModel.type == kMerchantDetailType_Othershop) {
        _cellButton.userInteractionEnabled = NO;
    }else{
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
}

-(void)cellButtonClicked{
    if (_cellType == OneLineCellTypeAddress) {
        if (self.location.latitude == 0.0f || self.location.longitude == 0.0f) {
            return;
        }
        RCMapViewController *vc = [[RCMapViewController alloc]initWithCoor:self.location andName:self.merchantName];
        [self.parentViewController.navigationController pushViewController:vc animated:YES];
        [vc release];
        return;
    }else if (_cellType == OneLineCellTypePhone){
        UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"电话" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
        NSString *phoneString = self.dataModel.content;
        phoneString = [phoneString stringByReplacingOccurrencesOfString:@"，" withString:@","];
        NSArray *phoneNumberArray = nil;
        NSRange range = [phoneString rangeOfString:@","];
        if (range.location != NSNotFound) {
            phoneNumberArray = [phoneString componentsSeparatedByString:@","];
        }else{
            NSRange range = [phoneString rangeOfString:@"/"];
            if (range.location != NSNotFound) {
                phoneNumberArray = [phoneString componentsSeparatedByString:@"/"];
            }else{
               phoneNumberArray = [phoneString componentsSeparatedByString:@" "];
            }
            
        }
        
        for (NSString *content in phoneNumberArray) {
            if ([NSString stringIsNullOrEmpty:content]) {
                continue;
            }
            [sheet addButtonWithTitle:content];
        }
        sheet.cancelButtonIndex = [sheet addButtonWithTitle:@"取消"];
        [sheet showFromTabBar:self.parentViewController.tabBarController.tabBar];
        [sheet release];
    }else if (_cellType == OneLineCellTypeOrder){
        
        if (![[GloableEngineService sharedInstance]alertLoginViewIfUnlogin:self.parentViewController]) {
            return;
        }
//        RCOrderVC *orderVC = [[RCOrderVC alloc]initWithShopID:self.merchantID];
        RCActivityOrderViewController *orderVC = [[RCActivityOrderViewController alloc]initWithShopID:self.merchantID];
        [self.parentViewController.navigationController pushViewController:orderVC animated:YES];
        [orderVC release];
    }else if (_cellType == OneLineCellTypeOrderServe){
        RCMemberCardVC *memberVC = [[RCMemberCardVC alloc]init];
        [self.parentViewController.navigationController pushViewController:memberVC animated:YES];
        [memberVC release];
    }
    
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex != actionSheet.cancelButtonIndex) {
        NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];
        if (_phoneWebView == nil) {
            _phoneWebView = [[UIWebView alloc] init];
            
        }
        title = [title stringByReplacingOccurrencesOfString:@" " withString:@""];
        NSURL *phone = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",title]];
        
        [_phoneWebView loadRequest:[NSURLRequest requestWithURL:phone]];
    }
}

+ (CGFloat) cellHeightWithString:(RCMerchantDetailItem *)detailModel
{
    if (nil == detailModel) {
        return 41;
    }
    
    TTTAttributedLabel *label = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(30, 13, 140, 100)];
    label.leading = 6;
    label.numberOfLines = 0;
    label.font = [UIFont fontWithName:kFontNameLightHeiti size:15];
    label.textColor = [UIColor colorWithHex:0xff505050];
    label.backgroundColor = [UIColor clearColor];
    
    if (detailModel.type == kMerchantDetailType_Address) {
        label.frame = CGRectMake(30, 13, 250, 100);
    }else if (detailModel.type == kMerchantDetailType_Order || detailModel.type == kMerchantDetailType_Othershop || detailModel.type == kMerchantDetailType_Traffic){
        
        [label release];
        return 41;
    }else{
        label.frame = CGRectMake(30, 13, 140, 100);
    }
    
    label.text = detailModel.content;
    NSAttributedString *attributedStr = label.attributedText;
    CGSize restSize = [attributedStr sizeWithConstrainedToSize:CGSizeMake(label.frame.size.width, 2000) Leading:6];
    [label release];
  
    return 13 + restSize.height + 13;

}


@end


@implementation RCMerchantDetailTwolineCell{
    UIImageView *_iconImageView;
    UILabel *_typeTitleLabel;
    TTTAttributedLabel *_typeContentLabel;
    UIImageView *_lineImageView;
}

- (id) initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]];
        self.layer.contents = (id)bgImage.CGImage;
        [self.contentView setBackgroundColorWithImage:bgImage];
        [self setUpView];
    }
    return self;
}


- (void) setUpView
{
    
    _iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(14, 13, 12, 12)];
    _iconImageView.backgroundColor = [UIColor clearColor];
    [self addSubview:_iconImageView];
    [_iconImageView release];
    
    _typeTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 13, 150, 17)];
    _typeTitleLabel.font = [UIFont fontWithName:kFontNameHeiti size:17];
    _typeTitleLabel.textColor = [UIColor colorWithHex:0xff505050];
    _typeTitleLabel.backgroundColor = [UIColor clearColor];
    [self addSubview:_typeTitleLabel];
    [_typeTitleLabel release];
    
    
    _typeContentLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(14, 34, 290, 200)];
    _typeContentLabel.font = [UIFont fontWithName:kFontNameHeiti size:15];
    _typeContentLabel.textColor = [UIColor colorWithHex:0xff989797];
    _typeContentLabel.numberOfLines = 0;
    _typeContentLabel.leading = 6;
    _typeContentLabel.backgroundColor = [UIColor clearColor];
    [self addSubview:_typeContentLabel];
    [_typeContentLabel release];
    
    _lineImageView = [[UIImageView alloc]init];
    _lineImageView.backgroundColor = [UIColor clearColor];
    NSString *filePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kLineImageFile];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
    [self addSubview:_lineImageView];
    [_lineImageView release];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;

    
}
- (void) bindData:(RCMerchantDetailItem *)detailModel
{
    if (nil == detailModel) {
        return;
    }
    
    _typeContentLabel.textColor = [UIColor colorWithHex:0xff989797];
    
    if (![NSString stringIsNullOrEmpty:detailModel.title]) {
        _typeTitleLabel.text = detailModel.title;
        NSString *resourcePath = [[NSBundle mainBundle]resourcePath];
        
        if ([detailModel.title isEqualToString:@"最新优惠"]) {
            NSString *filePath = [resourcePath stringByAppendingPathComponent:kHighlightImageFile];
            [_iconImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
            _typeContentLabel.textColor = [UIColor colorWithHex:0xffff6800];
            
        }else if ([detailModel.title isEqualToString:@"营业时间"]){
            NSString *filePath = [resourcePath stringByAppendingPathComponent:kOpentimeImageFile];
            [_iconImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
        }else if ([detailModel.title isEqualToString:@"商户简介"]){
            NSString *filePath = [resourcePath stringByAppendingPathComponent:kDescImageFile];
            [_iconImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
        }else{
            NSString *filePath = [resourcePath stringByAppendingPathComponent:kDescImageFile];
            [_iconImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
        }
    }else{
        _typeTitleLabel.text = @"";
        [_iconImageView setImage:nil];
    }
    
    
    
    _typeContentLabel.text = detailModel.content;

    NSAttributedString *attributedStr = _typeContentLabel.attributedText;
    CGSize restSize = [attributedStr sizeWithConstrainedToSize:CGSizeMake(290, 2000) Leading:6];
    _typeContentLabel.frame = CGRectMake(14, 34, 290, restSize.height);
    _lineImageView.frame  = CGRectMake(0, 34+restSize.height+14, 320, 1);
}

+ (CGFloat) cellHeightWithString:(NSString *)str
{
    TTTAttributedLabel *label = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(14, 34, 290, 200)];
    label.font = [UIFont fontWithName:kFontNameHeiti size:15];
    label.textColor = [UIColor colorWithHex:0xff989797];
    label.numberOfLines = 0;
    label.leading = 6;
    label.backgroundColor = [UIColor clearColor];
    label.text = str;
    NSAttributedString *attributedStr = label.attributedText;
    CGSize restSize = [attributedStr sizeWithConstrainedToSize:CGSizeMake(290, 2000) Leading:6];
    [label release];
    return 34 + restSize.height + 15;
    
}


@end


@implementation RCMerchantDetailRecommendCell{
    
    UILabel *_typeTitleLabel;
    TTTAttributedLabel *_typeContentLabel;
    UIImageView *_lineImageView;
    UIImageView *_arrowImageView;
}

- (id) initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]];
        self.layer.contents = (id)bgImage.CGImage;
        [self.contentView setBackgroundColorWithImage:bgImage];
        [self setUpView];
    }
    return self;
}


- (void) setUpView
{
    
    
    _typeTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 13, 150, 17)];
    _typeTitleLabel.font = [UIFont fontWithName:kFontNameHeiti size:17];
    _typeTitleLabel.textColor = [UIColor colorWithHex:0xffff6800];
    _typeTitleLabel.backgroundColor = [UIColor clearColor];
    [self addSubview:_typeTitleLabel];
    [_typeTitleLabel release];
    
    
    _typeContentLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(14, 34, 265, 200)];
    _typeContentLabel.font = [UIFont fontWithName:kFontNameHeiti size:15];
    _typeContentLabel.textColor = [UIColor colorWithHex:0xff505050];
    _typeContentLabel.numberOfLines = 0;
    _typeContentLabel.leading = 6;
    _typeContentLabel.backgroundColor = [UIColor clearColor];
    [self addSubview:_typeContentLabel];
    [_typeContentLabel release];
    
    _lineImageView = [[UIImageView alloc]init];
    _lineImageView.backgroundColor = [UIColor clearColor];
    NSString *filePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kLineImageFile];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
    [self addSubview:_lineImageView];
    [_lineImageView release];
    
    _arrowImageView.backgroundColor = [UIColor clearColor];
    NSString *arrowPath = [[NSBundle mainBundle]pathForResource:kCellArrowImageFile ofType:nil];
    [_arrowImageView setImage:[UIImage imageWithContentsOfFile:arrowPath]];
    [self addSubview:_arrowImageView];
    [_arrowImageView release];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
}
- (void) bindData:(RCMerchantDetailItem *)detailModel
{
    if (nil == detailModel) {
        return;
    }
    
    if (![NSString stringIsNullOrEmpty:detailModel.title]) {
        _typeTitleLabel.text = detailModel.title;
        
    }else{
        _typeTitleLabel.text = @"";

    }
    
    
    
    _typeContentLabel.text = detailModel.content;
    
    NSAttributedString *attributedStr = _typeContentLabel.attributedText;
    CGSize restSize = [attributedStr sizeWithConstrainedToSize:CGSizeMake(265, 2000) Leading:6];
    _typeContentLabel.frame = CGRectMake(14, 34, 290, restSize.height);
    _lineImageView.frame  = CGRectMake(0, 34+restSize.height+14, 320, 1);
    _arrowImageView.frame = CGRectMake(299, (34+restSize.height+14-10)/2, 7, 10);
}

+ (CGFloat) cellHeightWithString:(NSString *)str
{
    TTTAttributedLabel *label = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(14, 34, 265, 200)];
    label.font = [UIFont fontWithName:kFontNameHeiti size:15];
    label.textColor = [UIColor colorWithHex:0xff505050];
    label.numberOfLines = 0;
    label.leading = 6;
    label.backgroundColor = [UIColor clearColor];
    label.text = str;
    NSAttributedString *attributedStr = label.attributedText;
    CGSize restSize = [attributedStr sizeWithConstrainedToSize:CGSizeMake(265, 2000) Leading:6];
    [label release];
    return 34 + restSize.height + 15;
    
}


@end

@implementation RCMerchantDetailCommentCell{
    
    UILabel *_typeTitleLabel;
    TTTAttributedLabel *_typeContentLabel;
    UIImageView *_lineImageView;
    UIImageView *_arrowImageView;
    UIImageView *_startImageView1;
    UIImageView *_startImageView2;
    UIImageView *_startImageView3;
    UIImageView *_startImageView4;
    UIImageView *_startImageView5;
    UILabel     *_userNameLabel;
    UIView      *_medalsView;
    UILabel     *_timeLabel;
}

- (id) initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]];
        self.layer.contents = (id)bgImage.CGImage;
        [self.contentView setBackgroundColorWithImage:bgImage];
        [self setUpView];
    }
    return self;
}

-(void)dealloc{
    [super dealloc];
}


- (void) setUpView
{
    
    
    _typeTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 13, 150, 17)];
    _typeTitleLabel.font = [UIFont fontWithName:kFontNameHeiti size:17];
    _typeTitleLabel.textColor = [UIColor colorWithHex:0xffff6800];
    _typeTitleLabel.backgroundColor = [UIColor clearColor];
    [self addSubview:_typeTitleLabel];
    [_typeTitleLabel release];
    
    _userNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 33, 100, 15)];
    _userNameLabel.backgroundColor = [UIColor clearColor];
    _userNameLabel.textColor = [UIColor colorWithHex:0xff505050];
    _userNameLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:15];
    [self addSubview:_userNameLabel];
    [_userNameLabel release];
    
    _medalsView = [[UIView alloc]initWithFrame:CGRectMake(140, 34, 100, 14)];
    _medalsView.backgroundColor = [UIColor clearColor];
    [self addSubview:_medalsView];
    [_medalsView release];
    
    _startImageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(14, 52, 14, 14)];
    _startImageView1.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView1];
    [_startImageView1 release];
    
    _startImageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(29, 52, 14, 14)];
    _startImageView2.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView2];
    [_startImageView2 release];
    
    _startImageView3 = [[UIImageView alloc]initWithFrame:CGRectMake(44, 52, 14, 14)];
    _startImageView3.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView3];
    [_startImageView3 release];
    
    _startImageView4 = [[UIImageView alloc]initWithFrame:CGRectMake(59, 52, 14, 14)];
    _startImageView4.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView4];
    [_startImageView4 release];
    
    _startImageView5 = [[UIImageView alloc]initWithFrame:CGRectMake(74, 52, 14, 14)];
    _startImageView5.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView5];
    [_startImageView5 release];
    
    
    _typeContentLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(14, 76, 265, 200)];
    _typeContentLabel.font = [UIFont fontWithName:kFontNameHeiti size:15];
    _typeContentLabel.textColor = [UIColor colorWithHex:0xff505050];
    _typeContentLabel.numberOfLines = 0;
    _typeContentLabel.leading = 6;
    _typeContentLabel.backgroundColor = [UIColor clearColor];
    [self addSubview:_typeContentLabel];
    [_typeContentLabel release];
    
    _timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 100, 150, 14)];
    _timeLabel.backgroundColor = [UIColor clearColor];
    _timeLabel.textColor = [UIColor colorWithHex:0xff737373];
    _timeLabel.font = [UIFont fontWithName:kFontNameHelvetica size:14];
    [self addSubview:_timeLabel];
    [_timeLabel release];
    
    _lineImageView = [[UIImageView alloc]init];
    _lineImageView.backgroundColor = [UIColor clearColor];
    NSString *filePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kLineImageFile];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
    [self addSubview:_lineImageView];
    [_lineImageView release];
    
    _arrowImageView.backgroundColor = [UIColor clearColor];
    NSString *arrowPath = [[NSBundle mainBundle]pathForResource:kCellArrowImageFile ofType:nil];
    [_arrowImageView setImage:[UIImage imageWithContentsOfFile:arrowPath]];
    [self addSubview:_arrowImageView];
    [_arrowImageView release];
      
    
}
- (void) bindData:(RCMerchantDetailItem *)detailModel
{
    if (nil == detailModel) {
        return;
    }
    if (![NSString stringIsNullOrEmpty:detailModel.title]) {
        _typeTitleLabel.text = [NSString stringWithFormat:@"%@(共%d条)",detailModel.title,detailModel.total];
        
    }else{
        _typeTitleLabel.text = @"";
        
    }
    
    if (![NSString stringIsNullOrEmpty:detailModel.userName]) {
        _userNameLabel.text = detailModel.userName;
    }else{
        _userNameLabel.text = @"";
    }
    
    NSInteger score = detailModel.score;
    NSString *resourcePath = [[NSBundle mainBundle]resourcePath];
    UIImage *activeImage = [UIImage imageWithContentsOfFile:[resourcePath stringByAppendingPathComponent:kStartActiveImageFile]];
    UIImage *inactiveImage = [UIImage imageWithContentsOfFile:[resourcePath stringByAppendingPathComponent:kStartInActiveImageFile]];
    [_startImageView1 setImage:score > 0 ? activeImage : inactiveImage];
    [_startImageView2 setImage:score > 1 ? activeImage : inactiveImage];
    [_startImageView3 setImage:score > 2 ? activeImage : inactiveImage];
    [_startImageView4 setImage:score > 3 ? activeImage : inactiveImage];
    [_startImageView5 setImage:score > 4 ? activeImage : inactiveImage];
    
    _typeContentLabel.text = detailModel.content;
    
    NSAttributedString *attributedStr = _typeContentLabel.attributedText;
    CGSize restSize = [attributedStr sizeWithConstrainedToSize:CGSizeMake(265, 2000) Leading:6];
    _typeContentLabel.frame = CGRectMake(14, 76, 290, restSize.height);
    
    _timeLabel.text = detailModel.dateTime;
    _timeLabel.frame = CGRectMake(14, CGRectGetMaxY(_typeContentLabel.frame)+10, 200, 14);
    
    _lineImageView.frame  = CGRectMake(0, 76+restSize.height+31, 320, 1);
    _arrowImageView.frame = CGRectMake(299, (76+restSize.height+32-10)/2, 7, 10);
}

+ (CGFloat) cellHeightWithString:(NSString *)str
{
    TTTAttributedLabel *label = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(14, 34, 265, 200)];
    label.font = [UIFont fontWithName:kFontNameHeiti size:15];
    label.textColor = [UIColor colorWithHex:0xff505050];
    label.numberOfLines = 0;
    label.leading = 6;
    label.backgroundColor = [UIColor clearColor];
    label.text = str;
    NSAttributedString *attributedStr = label.attributedText;
    CGSize restSize = [attributedStr sizeWithConstrainedToSize:CGSizeMake(265, 2000) Leading:6];
    [label release];
    return 76 + restSize.height + 32;
    
}

@end


@implementation RCMerchantDetailSignCell{
    UILabel *_typeTitleLabel;
    UIImageView *_profileImageView;
    UIImageView *_lineImageView;
    UIImageView *_arrowImageView;
    UIImageView *_startImageView1;
    UIImageView *_startImageView2;
    UIImageView *_startImageView3;
    UIImageView *_startImageView4;
    UIImageView *_startImageView5;
    UILabel     *_userNameLabel;
    UILabel     *_timeLabel;
    UILabel     *_signCountLabel;
}

- (id) initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]];
        self.layer.contents = (id)bgImage.CGImage;
        [self.contentView setBackgroundColorWithImage:bgImage];
        [self setUpView];
    }
    return self;
}


- (void) setUpView
{
    
    
    _typeTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 13, 250, 17)];
    _typeTitleLabel.font = [UIFont fontWithName:kFontNameHeiti size:17];
    _typeTitleLabel.textColor = [UIColor colorWithHex:0xffff6800];
    _typeTitleLabel.backgroundColor = [UIColor clearColor];
    [self addSubview:_typeTitleLabel];
    [_typeTitleLabel release];
    
    _profileImageView = [[UIImageView alloc]initWithFrame:CGRectMake(22, 34, 35, 35)];
    _profileImageView.backgroundColor = [UIColor clearColor];
    [self addSubview:_profileImageView];
    [_profileImageView release];
    
    _userNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(65, 37, 100, 15)];
    _userNameLabel.backgroundColor = [UIColor clearColor];
    _userNameLabel.textColor = [UIColor colorWithHex:0xff505050];
    _userNameLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    [self addSubview:_userNameLabel];
    [_userNameLabel release];
    
    
    
    _startImageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(65, 55, 14, 14)];
    _startImageView1.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView1];
    [_startImageView1 release];
    
    _startImageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(80, 55, 14, 14)];
    _startImageView2.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView2];
    [_startImageView2 release];
    
    _startImageView3 = [[UIImageView alloc]initWithFrame:CGRectMake(95, 55, 14, 14)];
    _startImageView3.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView3];
    [_startImageView3 release];
    
    _startImageView4 = [[UIImageView alloc]initWithFrame:CGRectMake(110, 55, 14, 14)];
    _startImageView4.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView4];
    [_startImageView4 release];
    
    _startImageView5 = [[UIImageView alloc]initWithFrame:CGRectMake(125, 55, 14, 14)];
    _startImageView5.backgroundColor = [UIColor clearColor];
    [self addSubview:_startImageView5];
    [_startImageView5 release];
    
    _timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(65, 75, 40, 14)];
    _timeLabel.backgroundColor = [UIColor clearColor];
    _timeLabel.textColor = [UIColor colorWithHex:0xff737373];
    _timeLabel.font = [UIFont fontWithName:kFontNameHelvetica size:14];
    [self addSubview:_timeLabel];
    [_timeLabel release];
    
    _signCountLabel = [[UILabel alloc]initWithFrame:CGRectMake(110, 75, 150, 14)];
    _signCountLabel.backgroundColor = [UIColor clearColor];
    _signCountLabel.textColor = [UIColor colorWithHex:0xff737373];
    _signCountLabel.font = [UIFont fontWithName:kFontNameHelvetica size:14];
    [self addSubview:_signCountLabel];
    [_signCountLabel release];
    
    _lineImageView = [[UIImageView alloc]init];
    _lineImageView.backgroundColor = [UIColor clearColor];
    NSString *filePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kLineImageFile];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
    [self addSubview:_lineImageView];
    [_lineImageView release];
    
    _arrowImageView.backgroundColor = [UIColor clearColor];
    NSString *arrowPath = [[NSBundle mainBundle]pathForResource:kCellArrowImageFile ofType:nil];
    [_arrowImageView setImage:[UIImage imageWithContentsOfFile:arrowPath]];
    [self addSubview:_arrowImageView];
    [_arrowImageView release];
    
    
}
- (void) bindData:(RCMerchantDetailItem *)detailModel
{
    if (nil == detailModel) {
        return;
    }
    
    if (![NSString stringIsNullOrEmpty:detailModel.title]) {
        _typeTitleLabel.text = [NSString stringWithFormat:@"签到留言墙（共%d人）",detailModel.total];
        
    }else{
        _typeTitleLabel.text = @"";
        
    }
    
    
    [_profileImageView setImage:[UIImage imageNamed:kAvatarDefaultImageFile]];
    if (![NSString stringIsNullOrEmpty:detailModel.avatar]) {
        [_profileImageView setImageWithURL:[NSURL URLWithString:detailModel.avatar] placeholderImage:[UIImage imageNamed:kAvatarDefaultImageFile]];
    }
    
    if (![NSString stringIsNullOrEmpty:detailModel.userName]) {
        _userNameLabel.text = detailModel.userName;
    }else{
        _userNameLabel.text = @"";
    }
    
    NSInteger score = detailModel.score;
    NSString *resourcePath = [[NSBundle mainBundle]resourcePath];
    UIImage *activeImage = [UIImage imageWithContentsOfFile:[resourcePath stringByAppendingPathComponent:kStartActiveImageFile]];
    UIImage *inactiveImage = [UIImage imageWithContentsOfFile:[resourcePath stringByAppendingPathComponent:kStartInActiveImageFile]];
    [_startImageView1 setImage:score > 0 ? activeImage : inactiveImage];
    [_startImageView2 setImage:score > 1 ? activeImage : inactiveImage];
    [_startImageView3 setImage:score > 2 ? activeImage : inactiveImage];
    [_startImageView4 setImage:score > 3 ? activeImage : inactiveImage];
    [_startImageView5 setImage:score > 4 ? activeImage : inactiveImage];
    
    CGFloat width = 65;
    if (![NSString stringIsNullOrEmpty:detailModel.dateTime]) {
        _timeLabel.text = detailModel.dateTime;
        CGSize timeSize = [_timeLabel.text sizeWithFont:_timeLabel.font constrainedToSize:CGSizeMake(200, 200)];
        _timeLabel.frame = CGRectMake(65, 75, timeSize.width, 14);
        
        width +=timeSize.width +10;
    }
    
    if (detailModel.score > 0) {
        _signCountLabel.text = [NSString stringWithFormat:@"共签到%d次",detailModel.score];
        _signCountLabel.frame = CGRectMake(width, 75, 320-width, 14);
    }
    

    _lineImageView.frame  = CGRectMake(0, 99, 320, 1);
    _arrowImageView.frame = CGRectMake(299, 45, 7, 10);
}

+ (CGFloat) cellHeight
{
    return 100;
    
}

@end


@implementation RCMerchantDetailPeripheryCell{
    UILabel *_typeNameLabel;
    UIImageView *_foodImageView;
    UILabel *_foodLabel;
    UIImageView *_sceneImageView;
    UILabel *_sceneLabel;
    UIImageView *_hotelImageView;
    UILabel *_hotelLabel;
    UIImageView *_allImageView;
    UILabel *_allLabel;
    UIImageView *_verticalLineView;
    UIImageView *_horizonLineView;
    UIImageView *_lineImageView;
}
@synthesize delegate = _delegate;

- (id) initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]];
        self.layer.contents = (id)bgImage.CGImage;
        [self.contentView setBackgroundColorWithImage:bgImage];
        [self setUpView];
    }
    return self;
}


- (void) setUpView
{
    _typeNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(13, 14, 100, 15)];
    _typeNameLabel.backgroundColor = [UIColor clearColor];
    _typeNameLabel.textColor = [UIColor colorWithHex:0xffff6800];
    _typeNameLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:15];
    _typeNameLabel.text = @"周边商户";
    [self addSubview:_typeNameLabel];
    [_typeNameLabel release];
    
    _foodImageView = [[UIImageView alloc]initWithFrame:CGRectMake(40, 33, 41, 32)];
    _foodImageView.backgroundColor = [UIColor clearColor];
    NSString *foodPath = [[NSBundle mainBundle]pathForResource:@"image_merchant_detail_periphery_food.png" ofType:nil];
    [_foodImageView setImage:[UIImage imageWithContentsOfFile:foodPath]];
    [self addSubview:_foodImageView];
    [_foodImageView release];
    
    _foodLabel = [[UILabel alloc]initWithFrame:CGRectMake(95, 41, 40, 17)];
    _foodLabel.backgroundColor = [UIColor clearColor];
    _foodLabel.textColor = [UIColor colorWithHex:0xff505050];
    _foodLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:17];
    _foodLabel.text = @"美食";
    [self addSubview:_foodLabel];
    [_foodLabel release];
    
    UIButton *foodTransparentButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 27, 160, 44)];
    foodTransparentButton.backgroundColor = [UIColor clearColor];
    foodTransparentButton.tag = 1;
    [foodTransparentButton addTarget:self action:@selector(transparentButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:foodTransparentButton];
    [foodTransparentButton release];
    
    _sceneImageView = [[UIImageView alloc]initWithFrame:CGRectMake(200, 33, 42, 32)];
    _sceneImageView.backgroundColor = [UIColor clearColor];
    NSString *scenePath = [[NSBundle mainBundle]pathForResource:@"image_merchant_detail_periphery_scene.png" ofType:nil];
    [_sceneImageView setImage:[UIImage imageWithContentsOfFile:scenePath]];
    [self addSubview:_sceneImageView];
    [_sceneImageView release];
    
    _sceneLabel = [[UILabel alloc]initWithFrame:CGRectMake(255, 41, 40, 17)];
    _sceneLabel.backgroundColor = [UIColor clearColor];
    _sceneLabel.textColor = [UIColor colorWithHex:0xff505050];
    _sceneLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:17];
    _sceneLabel.text = @"景点";
    [self addSubview:_sceneLabel];
    [_sceneLabel release];
    
    UIButton *sceneTransparentButton = [[UIButton alloc]initWithFrame:CGRectMake(160, 27, 160, 44)];
    sceneTransparentButton.backgroundColor = [UIColor clearColor];
    sceneTransparentButton.tag = 2;
    [sceneTransparentButton addTarget:self action:@selector(transparentButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:sceneTransparentButton];
    [sceneTransparentButton release];
    
    _hotelImageView = [[UIImageView alloc]initWithFrame:CGRectMake(45, 97, 33, 33)];
    _hotelImageView.backgroundColor = [UIColor clearColor];
    NSString *hotelPath = [[NSBundle mainBundle]pathForResource:@"image_merchant_detail_periphery_hotel.png" ofType:nil];
    [_hotelImageView setImage:[UIImage imageWithContentsOfFile:hotelPath]];
    [self addSubview:_hotelImageView];
    [_hotelImageView release];
    
    _hotelLabel = [[UILabel alloc]initWithFrame:CGRectMake(95, 105, 40, 17)];
    _hotelLabel.backgroundColor = [UIColor clearColor];
    _hotelLabel.textColor = [UIColor colorWithHex:0xff505050];
    _hotelLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:17];
    _hotelLabel.text = @"酒店";
    [self addSubview:_hotelLabel];
    [_hotelLabel release];
    
    UIButton *hotelTransparentButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 90, 160, 47)];
    hotelTransparentButton.backgroundColor = [UIColor clearColor];
    hotelTransparentButton.tag = 3;
    [hotelTransparentButton addTarget:self action:@selector(transparentButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:hotelTransparentButton];
    [hotelTransparentButton release];
    
    _allImageView = [[UIImageView alloc]initWithFrame:CGRectMake(200, 97, 38, 33)];
    _allImageView.backgroundColor = [UIColor clearColor];
    NSString *allPath = [[NSBundle mainBundle]pathForResource:@"search_tu005.png" ofType:nil];
    [_allImageView setImage:[UIImage imageWithContentsOfFile:allPath]];
    [self addSubview:_allImageView];
    [_allImageView release];
    
    _allLabel = [[UILabel alloc]initWithFrame:CGRectMake(255, 108, 40, 17)];
    _allLabel.backgroundColor = [UIColor clearColor];
    _allLabel.textColor = [UIColor colorWithHex:0xff505050];
    _allLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:17];
    _allLabel.text = @"娱乐";
    [self addSubview:_allLabel];
    [_allLabel release];
    
    UIButton *allTransparentButton = [[UIButton alloc]initWithFrame:CGRectMake(160, 90, 160, 47)];
    allTransparentButton.backgroundColor = [UIColor clearColor];
    allTransparentButton.tag = 4;
    [allTransparentButton addTarget:self action:@selector(transparentButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:allTransparentButton];
    [allTransparentButton release];
    
    _lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 149, 320, 1)];
    _lineImageView.backgroundColor = [UIColor clearColor];
    NSString *filePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kLineImageFile];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
    [self addSubview:_lineImageView];
    [_lineImageView release];
    
    _horizonLineView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 74, 320, 1)];
    _horizonLineView.backgroundColor = [UIColor clearColor];
     NSString *horizonPath = [[NSBundle mainBundle]pathForResource:@"image_merchant_detail_horizonLine.png" ofType:nil];
    [_horizonLineView setImage:[UIImage imageWithContentsOfFile:horizonPath]];
    [self addSubview:_horizonLineView];
    [_horizonLineView release];
    
    _verticalLineView = [[UIImageView alloc]initWithFrame:CGRectMake(159, 30, 1, 115)];
    _verticalLineView.backgroundColor = [UIColor clearColor];
    NSString *verticalPath = [[NSBundle mainBundle]pathForResource:@"image_merchant_detail_verticalLine.png" ofType:nil];
    [_verticalLineView setImage:[UIImage imageWithContentsOfFile:verticalPath]];
    [self addSubview:_verticalLineView];
    [_verticalLineView release];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
}


+ (CGFloat) cellHeight
{
    return 150;
    
}

-(void)transparentButtonClicked:(id)sender{
    UIButton *button = (UIButton *)sender;
    if (_delegate && [_delegate respondsToSelector:@selector(gotoMerchantNearbyWithTag:)]) {
        [_delegate gotoMerchantNearbyWithTag:button.tag];
    }
}

@end


@implementation RCMerchantDiscoutCell{
    UILabel *_typeTitleLabel;
    TTTAttributedLabel *_typeContentLabel;
    UIImageView *_lineImageView;
    UIView *_bgimageView;
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
//        UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]];
//        self.layer.contents = (id)bgImage.CGImage;
//        [self.contentView setBackgroundColorWithImage:bgImage];
        [self createPlaceHolderView];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
    
}

-(void)createPlaceHolderView{
    
    _bgimageView = [[UIView alloc]init];
    [_bgimageView setBackgroundColor:[UIColor colorWithHex:0xfff6f6f6]];
    [self addSubview:_bgimageView];
    [_bgimageView release];
    
    _typeTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 13, 150, 17)];
    _typeTitleLabel.font = [UIFont fontWithName:kFontNameHeiti size:17];
    _typeTitleLabel.textColor = [UIColor colorWithHex:0xff505050];
    _typeTitleLabel.backgroundColor = [UIColor clearColor];
    [self addSubview:_typeTitleLabel];
    [_typeTitleLabel release];
    
    
    _typeContentLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(14, 34, 290, 200)];
    _typeContentLabel.font = [UIFont fontWithName:kFontNameHeiti size:15];
    _typeContentLabel.textColor = [UIColor colorWithHex:0xff989797];
    _typeContentLabel.numberOfLines = 0;
    _typeContentLabel.leading = 6;
    _typeContentLabel.backgroundColor = [UIColor clearColor];
    [self addSubview:_typeContentLabel];
    [_typeContentLabel release];
    
    _lineImageView = [[UIImageView alloc]init];
    _lineImageView.backgroundColor = [UIColor clearColor];
    NSString *filePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kLineImageFile];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
    [self addSubview:_lineImageView];
    [_lineImageView release];
}

-(void)bindData:(RCMerchantDetailItem *)detailModel{
    if (nil == detailModel) {
        return;
    }
    
    _typeContentLabel.textColor = [UIColor colorWithHex:0xff989797];
    
    if (![NSString stringIsNullOrEmpty:detailModel.title]) {
        _typeTitleLabel.text = detailModel.title;
        
    }else{
        _typeTitleLabel.text = @"";
    
    }
    
    
    
    _typeContentLabel.text = detailModel.content;
    
    NSAttributedString *attributedStr = _typeContentLabel.attributedText;
    CGSize restSize = [attributedStr sizeWithConstrainedToSize:CGSizeMake(290, 2000) Leading:6];
    _typeContentLabel.frame = CGRectMake(14, 34, 290, restSize.height);
    
    CGFloat height = CGRectGetMaxY(_typeContentLabel.frame);
    
    if (detailModel.picArray != nil && [detailModel.picArray count] >0) {
        
        for (int i = 0; i < [detailModel.picArray count]; i++) {
            NSString *picUrl = [detailModel.picArray safeObjectAtIndex:i];
            if ([NSString stringIsNullOrEmpty:picUrl]) {
                continue;
            }
            
            UIImageView *defaultImageView = [[UIImageView alloc]initWithFrame:CGRectMake(14, height +12, 290, 145)];
            defaultImageView.backgroundColor = [UIColor clearColor];
            UIImage *defaultImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kDefaultimageFile ofType:nil]];
            defaultImage = [defaultImage resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
            [defaultImageView setImage:defaultImage];
            
            UIImageView *picImageView = [[UIImageView alloc]initWithFrame:CGRectMake(3, 3, 284, 139)];
            picImageView.backgroundColor = [UIColor clearColor];
            [picImageView setImageWithURL:[NSURL URLWithString:picUrl] placeholderImage:nil];
            [defaultImageView addSubview:picImageView];
            [picImageView release];
            
            [self addSubview:defaultImageView];
            [defaultImageView release];
            height +=157;
        }
        
        
    }
    
    
    
    _lineImageView.frame  = CGRectMake(0, height+14, 320, 1);
    _bgimageView.frame = CGRectMake(0, 0, 320, height+15);

}

+(CGFloat)getCellHeight:(RCMerchantDetailItem *)detailModel{
    if (nil == detailModel) {
        return 0.0;
    }
    
    TTTAttributedLabel *label = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(14, 34, 290, 200)];
    label.font = [UIFont fontWithName:kFontNameHeiti size:15];
    label.textColor = [UIColor colorWithHex:0xff989797];
    label.numberOfLines = 0;
    label.leading = 6;
    label.backgroundColor = [UIColor clearColor];
    label.text = detailModel.content;
    NSAttributedString *attributedStr = label.attributedText;
    CGSize restSize = [attributedStr sizeWithConstrainedToSize:CGSizeMake(290, 2000) Leading:6];
    [label release];
    
    CGFloat height = 34 + restSize.height;
    
    if (detailModel.picArray != nil && [detailModel.picArray count] >0) {
        
        for (int i = 0; i < [detailModel.picArray count]; i++) {
            NSString *picUrl = [detailModel.picArray safeObjectAtIndex:i];
            if ([NSString stringIsNullOrEmpty:picUrl]) {
                continue;
            }
            
            height +=157;
        }
        
        
    }

    return height + 15;
}

@end

